/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package es.us.gestortareas.bean;

import es.us.gestortareas.entity.Tarea;
import es.us.gestortareas.entity.Usuario;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author Karmenchue
 */
@Stateless
public class TareaFacade extends AbstractFacade<Tarea> {
    @PersistenceContext(unitName = "GestorTareas-ejbPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public TareaFacade() {
        super(Tarea.class);
    }
    
    public List<Tarea> findByOwner(Usuario u){
        List<Tarea> res = null;
        Query q = em.createNamedQuery("Tarea.findAllTareasByUser");
        q.setParameter("usuario", u);
        res = q.getResultList();
        return res;               
    }
    
    public List<Tarea> findMyTasks(Usuario u){
        List<Tarea> res = null;
        Query q = em.createNamedQuery("Tarea.findMyTasks");
        q.setParameter("usuario", u);
        res = q.getResultList();
        return res;               
    }
    
    public Tarea update(Tarea t){
        return em.merge(t);
    }
    
    public void delete(Tarea t){
        em.remove(t);
    }
    
    public Tarea insert(Tarea t){
        return update(t);
    }
    
    
}
